package com.niit.activity3_6.service.impl;

import com.niit.activity3_6.dao.EmployeeDao;
import com.niit.activity3_6.domain.Employee;
import com.niit.activity3_6.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeDao employeeDao;
    @Override
    public Employee findOneById(String id){
        return employeeDao.findById(id).get();
    }
    @Override
    public List<Employee> findAll(){
        return employeeDao.findAll();
    }
    @Override
    @Transactional
    public void update(Employee employee){
        employeeDao.updateEmployee(employee.getId(),employee.getName(),employee.getGender(),employee.getTitle());
    }
    @Override
    public void deleteById(String id){
        employeeDao.deleteById(id);
    }
    @Override
    public void addEmployee(Employee employee){
        employeeDao.save(employee);
    }
    @Override
    public List<Employee> findManyByGender(String gender){
        return employeeDao.findAllByGender(gender);
    }
}
